package com.example.yucheng.mapper;

import com.example.yucheng.domain.ReceivingPrice;
import com.example.yucheng.util.PageQuery;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReceivingPriceMapper {

    @Select("SELECT receiving_price.u_id as uId,receiving_price.g_id as gId, receiving_price.per, receiving_price.id, stock.name as goodName ,receiving_price.cost_price,receiving_price.remark,receiving_unit.name as receivingUnit,category.name as categoryName FROM receiving_price,receiving_unit,category,stock where receiving_price.u_id = receiving_unit.id and receiving_price.g_id=stock.id and stock.c_id=category.id order by receiving_price.id desc ")
    public List<ReceivingPrice> getReceivingList();

    @Select("select cost_price from receiving_price where g_id=#{gId} and u_id=#{uId} and per=#{per}")
    public Integer getCostPrice(ReceivingPrice receivingPrice);

    @Select("SELECT receiving_price.u_id as uId,receiving_price.g_id as gId,receiving_price.per, receiving_price.id, stock.name as goodName ,receiving_price.cost_price,receiving_price.remark,receiving_unit.name as receivingUnit,category.name as categoryName FROM receiving_price,receiving_unit,category,stock where receiving_price.u_id = receiving_unit.id and receiving_price.g_id=stock.id and stock.c_id=category.id order by receiving_price.id desc  limit #{pageNum},#{pageSize}")
    public List<ReceivingPrice> getReceivingListByLimit(PageQuery pageQuery);

    @Delete("DELETE FROM  receiving_price WHERE id = #{id}")
    public boolean deleteReceivingPrice(@Param("id") int id);

    @Update("UPDATE receiving_price SET remark = #{remark},u_id = #{uId},g_id=#{gId},cost_price=#{costPrice},per=#{per} WHERE id = #{id}")
    public boolean updateReceivingPrice(ReceivingPrice receiving);

    @Insert("INSERT INTO receiving_price (u_id,g_id,cost_price,remark,per) VALUES( #{uId},#{gId},#{costPrice},#{remark},#{per})")
    public boolean insertReceivingPrice(ReceivingPrice receiving);

}
